/**
 * Created by wangshaohua on 2018/2/7.
 */
moduleLearningMap.controller("LanguageQuery", function (LanguageService, LanguageResource, $$CambioConfig, $scope, $log, $state, GeneralResource, LoadingService, ConstantService, DialogService) {
    initPage($scope);
    $scope.$on("$viewContentLoaded", function () {
        $scope.reset();
        pageOnLoad($scope);
        ConstantService.addState($state.current, true, LanguageService.language('语言管理'));
        $scope.query();
    });

    $scope.reset = function () {
        $scope.queryPara = {
            className: Models.Language.className,
            all: true
        };
    }

    $scope.query = function () {
        //LoadingService.show();
        GeneralResource.query({}, $scope.queryPara, function (queryResult) {
            $log.debug("查询结果", queryResult.data);
            $scope.queryResult = queryResult.data;
            //LoadingService.hide();
        });
    };

    $scope.removeLanguage = function (language) {
        Alert.confirm(function () {
            //LoadingService.show();
            //$scope.currentLanguage.projectName = $scope.currentLanguage.projectNameOption.value;
            LanguageResource.delete({id: language.id}, {}, function (htmlResult) {
                //$log.debug("h5项目更新结果", htmlResult);
                //angular.copy(htmlResult, $scope.currentHtml);
                $scope.query();
                Alert.success();
                //LoadingService.hide();
            }, function () {
                //LoadingService.hide();
            });
        })
    }

    $scope.detail = function (record) {
        $state.go('sz.languageDetailQuery', {
            languageViewId: record.id
        })
    };

    $scope.download = function (record) {
        if (!StringUtils.isNlOrUndOrEmpty(record.file)) {
            window.open($$CambioConfig.DOWNLOAD_URL.format({id: record.file}), '_blank');
        }
    };

    $scope.languageMgt = function () {
        $scope.currentLanguage = {};
        DialogService.open("languageMgt", $scope, function () {
            $scope.query()
        });
    }
    //$scope.query($scope.pagination.currentPageNo);
});